<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>dexterind-nxtchuck.h</h1>  </div>
</div>
<div class="contents">
<a href="dexterind-nxtchuck_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*!@addtogroup Dexter_Industries</span>
<a name="l00002"></a>00002 <span class="comment">* @{</span>
<a name="l00003"></a>00003 <span class="comment">* @defgroup NXTCHUCK NXTChuck Sensor</span>
<a name="l00004"></a>00004 <span class="comment">* Dexter Industries NXTChuck Sensor driver</span>
<a name="l00005"></a>00005 <span class="comment">* @{</span>
<a name="l00006"></a>00006 <span class="comment">*/</span>
<a name="l00007"></a>00007 <span class="comment">/*</span>
<a name="l00008"></a>00008 <span class="comment"> * $Id: dexterind-nxtchuck.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00009"></a>00009 <span class="comment"> */</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="preprocessor">#ifndef __NXTCHUCK_H__</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span><span class="preprocessor">#define __NXTCHUCK_H__</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="comment">/** \file dexterind-nxtchuck.h</span>
<a name="l00014"></a>00014 <span class="comment"> * \brief Dexter Industries NXTChuck Sensor driver</span>
<a name="l00015"></a>00015 <span class="comment"> *</span>
<a name="l00016"></a>00016 <span class="comment"> * dexterind-nxtchuck.h provides an API for the Dexter Industries NXTChuck Sensor.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * Changelog:</span>
<a name="l00019"></a>00019 <span class="comment"> * - 0.1: Initial release</span>
<a name="l00020"></a>00020 <span class="comment"> *</span>
<a name="l00021"></a>00021 <span class="comment"> * Credits:</span>
<a name="l00022"></a>00022 <span class="comment"> * - Big thanks to Dexter Industries for providing me with the hardware necessary to write and test this.</span>
<a name="l00023"></a>00023 <span class="comment"> *</span>
<a name="l00024"></a>00024 <span class="comment"> * License: You may use this code as you wish, provided you give credit where its due.</span>
<a name="l00025"></a>00025 <span class="comment"> *</span>
<a name="l00026"></a>00026 <span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<a name="l00027"></a>00027 <span class="comment"></span>
<a name="l00028"></a>00028 <span class="comment"> * \author Xander Soldaat (xander_at_botbench.com)</span>
<a name="l00029"></a>00029 <span class="comment"> * \date 02 November 2012</span>
<a name="l00030"></a>00030 <span class="comment"> * \version 0.1</span>
<a name="l00031"></a>00031 <span class="comment"> * \example dexterind-nxtchuck-test1.c</span>
<a name="l00032"></a>00032 <span class="comment"> */</span>
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="preprocessor">#pragma systemFile</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span>
<a name="l00036"></a>00036 <span class="preprocessor">#ifndef __COMMON_H__</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="common_8h.html" title="Commonly used functions used by drivers.">common.h</a>&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span>
<a name="l00040"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga868545de00c8a2cab5b51c3c32178c19">00040</a> <span class="preprocessor">#define NXTCHUCK_COM_ERROR                        0</span>
<a name="l00041"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga31e8d28723b9e486a3858bb345d03622">00041</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_COM_SUCCESS                      1</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span>
<a name="l00043"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga33b0a41cd83100cfdc42bc534d47e0f5">00043</a> <span class="preprocessor">#define NXTCHUCK_I2C_ADDRESS                      0xA4</span>
<a name="l00044"></a>00044 <span class="preprocessor"></span>
<a name="l00045"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gadfa14694b133a4c3cfdcb4e80548903e">00045</a> <span class="preprocessor">#define NXTCHUCK_DEVICE_UNKNOWN                   1</span>
<a name="l00046"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gac062f27792058c4f9e388932f0744cda">00046</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_NUNCHUK                   2</span>
<a name="l00047"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gac87c4f01df118eb5fb8b3252b5182e02">00047</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_CLASSIC_CONTROLLER        3</span>
<a name="l00048"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga767945595eed8b20843588e26ca89670">00048</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_GH_GUITAR                 4</span>
<a name="l00049"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga90f0d95861a568f347cbd8d4d4cf697d">00049</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_GH_DRUMS                  5</span>
<a name="l00050"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga0406afc8f5a03beda51cb4c1d67472f7">00050</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_DJH_TURNTABLE             6</span>
<a name="l00051"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gac0826fa67ab319717d431f1f1f957f52">00051</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_BALANCE_BOARD             7</span>
<a name="l00052"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga90d74a8ebe8dd12732a582b9390b657b">00052</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_MOTION_PLUS_ACTIVE        8</span>
<a name="l00053"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga152f75104ab7482a79338b7207874e28">00053</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_MOTION_PLUS_ACTIVE_N_PT   9</span>
<a name="l00054"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga343be2246da67d91812526b5cf9c9873">00054</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_MOTION_PLUS_ACTIVE_CC_PT  10</span>
<a name="l00055"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gaac3d73cae8c6f223aeacd4a66803d18c">00055</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_MOTION_PLUS_INACTIVE      11</span>
<a name="l00056"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gabb1f7de8dd66f531e699931fb0ace5f8">00056</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_MOTION_PLUS_NL_ACTIVE     12</span>
<a name="l00057"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga7b0b917c48dd97c4823d6c80094688c4">00057</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_MOTION_PLUS_NL_N_PT       13</span>
<a name="l00058"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga755c0565b786126ca21fe4a504ba2170">00058</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_MOTION_PLUS_NL_CC_PT      14</span>
<a name="l00059"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga818e442b60c6c0226e252ab4afecb0eb">00059</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_DEVICE_NUNCHUK_BLACK             15</span>
<a name="l00060"></a>00060 <span class="preprocessor"></span>
<a name="l00061"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga0db481094e42ec52acef7ea369fec78f">00061</a> <span class="preprocessor">#define NXTCHUCK_N_BTN_Z                          0x01</span>
<a name="l00062"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gabf57486ae72c2255ae1870b5f1b6d2d3">00062</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_N_BTN_C                          0x02</span>
<a name="l00063"></a>00063 <span class="preprocessor"></span>
<a name="l00064"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gad0a04982202449af8b35fccc3388d7e5">00064</a> <span class="preprocessor">#define NXTCHUCK_CC_BTN_RT 0x0002 // Right shoulder button</span>
<a name="l00065"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga9c48c4368a4519495ed768ce1dd2b54d">00065</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_P  0x0004 // Start button</span>
<a name="l00066"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gae87e9ee4f20c42e5f296827b08f69208">00066</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_H  0x0008 // Home button</span>
<a name="l00067"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga1586fe17dce7340e0b2374dc38e06cb3">00067</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_M  0x0010 // Select button</span>
<a name="l00068"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga2e68a6268d949d5bebe54c5a688ba293">00068</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_LT 0x0020 // Left Shoulder button</span>
<a name="l00069"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gaf9935a7d30f2ebeb442a403cf1a17557">00069</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_DD 0x0040 // d-pad down</span>
<a name="l00070"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gad0e67c5290b53525437db9005acefd69">00070</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_DR 0x0080 // d-pad right</span>
<a name="l00071"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gade1d4765de012f6b24581ef4f3f8225f">00071</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_DU 0x0100 // d-pad up</span>
<a name="l00072"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gac3e7e295b742d51958d4fc52754ecc80">00072</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_DL 0x0200 // d-pad left</span>
<a name="l00073"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga303bc585a2e2be5b2f1379ed36380393">00073</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_ZR 0x0400 // Right-Z button</span>
<a name="l00074"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga18688c1612146737edb1238d228cad62">00074</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_X  0x0800 // x button</span>
<a name="l00075"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gac62af2bf82e90f0d87345e50c5d90631">00075</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_A  0x1000 // a button</span>
<a name="l00076"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gab16f06d45d67248b1a3358687d13ac22">00076</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_Y  0x2000 // y button</span>
<a name="l00077"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga10574eabab0f5905a30bb98efa349e99">00077</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_B  0x4000 // b button</span>
<a name="l00078"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga012e8e7af66150e4b944c2698e37e31e">00078</a> <span class="preprocessor"></span><span class="preprocessor">#define NXTCHUCK_CC_BTN_ZL 0x8000 // Left-Z button</span>
<a name="l00079"></a>00079 <span class="preprocessor"></span>
<a name="l00080"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">00080</a> <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>;        <span class="comment">/*!&lt; Array to hold I2C command data */</span>
<a name="l00081"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">00081</a> <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>;          <span class="comment">/*!&lt; Array to hold I2C reply data */</span>
<a name="l00082"></a>00082 
<a name="l00083"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gad9e05a633482cf59f2ab2d4976d64bb1">00083</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t_c_h_u_c_k.html#gad9e05a633482cf59f2ab2d4976d64bb1">NXTCHUCKinitialised</a>[] = {<span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>};  <span class="comment">/*!&lt; Has the NXTChuck been initialised yet? */</span>
<a name="l00084"></a>00084 
<a name="l00085"></a><a class="code" href="structt_nunchuck.html">00085</a> <span class="keyword">typedef</span> <span class="keyword">struct</span>
<a name="l00086"></a>00086 {
<a name="l00087"></a><a class="code" href="structt_nunchuck.html#a52c92ae81f8d5f16d15422fb3838fe27">00087</a>   ubyte <a class="code" href="structt_nunchuck.html#a52c92ae81f8d5f16d15422fb3838fe27">ident</a>;
<a name="l00088"></a><a class="code" href="structt_nunchuck.html#aec86757fae7769579f06ae433a0a5d44">00088</a>   ubyte <a class="code" href="structt_nunchuck.html#aec86757fae7769579f06ae433a0a5d44">stickX</a>;
<a name="l00089"></a><a class="code" href="structt_nunchuck.html#a91804e03b8050dbb60a0097eda903f57">00089</a>   ubyte <a class="code" href="structt_nunchuck.html#a91804e03b8050dbb60a0097eda903f57">stickY</a>;
<a name="l00090"></a><a class="code" href="structt_nunchuck.html#aeb96883d9be554e3130dd8a074dd1181">00090</a>   <span class="keywordtype">int</span> <a class="code" href="structt_nunchuck.html#aeb96883d9be554e3130dd8a074dd1181">accelX</a>;
<a name="l00091"></a><a class="code" href="structt_nunchuck.html#aa79b1c1093bc17ca66f39fa286fb8c16">00091</a>   <span class="keywordtype">int</span> <a class="code" href="structt_nunchuck.html#aa79b1c1093bc17ca66f39fa286fb8c16">accelY</a>;
<a name="l00092"></a><a class="code" href="structt_nunchuck.html#ac1d83c37ada1e57ee781a2e8eea0472a">00092</a>   <span class="keywordtype">int</span> <a class="code" href="structt_nunchuck.html#ac1d83c37ada1e57ee781a2e8eea0472a">accelZ</a>;
<a name="l00093"></a><a class="code" href="structt_nunchuck.html#a739999c8e3c48d0a6a60783b778c4a6b">00093</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_nunchuck.html#a739999c8e3c48d0a6a60783b778c4a6b">buttonC</a>;
<a name="l00094"></a><a class="code" href="structt_nunchuck.html#ad21c5419fe7bae1473d6b2a153a89a2e">00094</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_nunchuck.html#ad21c5419fe7bae1473d6b2a153a89a2e">buttonZ</a>;
<a name="l00095"></a><a class="code" href="structt_nunchuck.html#acfe810cf5fd316d47ead62fa49987852">00095</a>   ubyte <a class="code" href="structt_nunchuck.html#acfe810cf5fd316d47ead62fa49987852">buttons</a>;
<a name="l00096"></a>00096 } <a class="code" href="structt_nunchuck.html">tNunchuck</a>;
<a name="l00097"></a>00097 
<a name="l00098"></a>00098 
<a name="l00099"></a><a class="code" href="structt_classic_ctrl.html">00099</a> <span class="keyword">typedef</span> <span class="keyword">struct</span>
<a name="l00100"></a>00100 {
<a name="l00101"></a><a class="code" href="structt_classic_ctrl.html#a9b14fccdc6066b2e7e3a5deea31b7567">00101</a>   byte <a class="code" href="structt_classic_ctrl.html#a9b14fccdc6066b2e7e3a5deea31b7567">stickLX</a>;
<a name="l00102"></a><a class="code" href="structt_classic_ctrl.html#ab96192459caf58af8ba8ed4d7367b4ee">00102</a>   byte <a class="code" href="structt_classic_ctrl.html#ab96192459caf58af8ba8ed4d7367b4ee">stickLY</a>;
<a name="l00103"></a><a class="code" href="structt_classic_ctrl.html#a2677c7490918757766a0f7b801602278">00103</a>   byte <a class="code" href="structt_classic_ctrl.html#a2677c7490918757766a0f7b801602278">stickRX</a>;
<a name="l00104"></a><a class="code" href="structt_classic_ctrl.html#a39a37e31fa3e3fae864ce87bcdb5ff71">00104</a>   byte <a class="code" href="structt_classic_ctrl.html#a39a37e31fa3e3fae864ce87bcdb5ff71">stickRY</a>;
<a name="l00105"></a><a class="code" href="structt_classic_ctrl.html#a212e8e42339fc291fd4406046df4f34a">00105</a>   byte <a class="code" href="structt_classic_ctrl.html#a212e8e42339fc291fd4406046df4f34a">triggerR</a>;
<a name="l00106"></a><a class="code" href="structt_classic_ctrl.html#a07c1c7c15c0af0dd74ce953e121efae5">00106</a>   byte <a class="code" href="structt_classic_ctrl.html#a07c1c7c15c0af0dd74ce953e121efae5">triggerL</a>;
<a name="l00107"></a><a class="code" href="structt_classic_ctrl.html#a8b6b2540b59302ca57e29f788de1c5cc">00107</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a8b6b2540b59302ca57e29f788de1c5cc">buttonTriggerR</a>;
<a name="l00108"></a><a class="code" href="structt_classic_ctrl.html#a9c7f8c6a2b4a93c605ba1083e98d1197">00108</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a9c7f8c6a2b4a93c605ba1083e98d1197">buttonTriggerL</a>;
<a name="l00109"></a><a class="code" href="structt_classic_ctrl.html#a6f435816b6dba2536203fe937c5a7905">00109</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a6f435816b6dba2536203fe937c5a7905">buttonDPadU</a>;
<a name="l00110"></a><a class="code" href="structt_classic_ctrl.html#a1ac9574aa7f0abb76f9ca882437aa661">00110</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a1ac9574aa7f0abb76f9ca882437aa661">buttonDPadD</a>;
<a name="l00111"></a><a class="code" href="structt_classic_ctrl.html#a35a67166ed212a30cbcb025c9a33488b">00111</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a35a67166ed212a30cbcb025c9a33488b">buttonDPadL</a>;
<a name="l00112"></a><a class="code" href="structt_classic_ctrl.html#abeb7d81a3d8ea072dbd803d84a36e7ad">00112</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#abeb7d81a3d8ea072dbd803d84a36e7ad">buttonDPadR</a>;
<a name="l00113"></a><a class="code" href="structt_classic_ctrl.html#a4b81f62849de94e99031a75408ed1c5b">00113</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a4b81f62849de94e99031a75408ed1c5b">buttonX</a>;
<a name="l00114"></a><a class="code" href="structt_classic_ctrl.html#a88fccb9b936b98239e4c80bb45a7f2e4">00114</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a88fccb9b936b98239e4c80bb45a7f2e4">buttonA</a>;
<a name="l00115"></a><a class="code" href="structt_classic_ctrl.html#a0a2aeff8c72c86f513929868343e5f60">00115</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a0a2aeff8c72c86f513929868343e5f60">buttonY</a>;
<a name="l00116"></a><a class="code" href="structt_classic_ctrl.html#a47d83cca9ce8707970aa544ef790997f">00116</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a47d83cca9ce8707970aa544ef790997f">buttonB</a>;
<a name="l00117"></a><a class="code" href="structt_classic_ctrl.html#a3fa408e11ec1e44f7a065534b7e9abb0">00117</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a3fa408e11ec1e44f7a065534b7e9abb0">buttonHome</a>;
<a name="l00118"></a><a class="code" href="structt_classic_ctrl.html#ab530dc092a31cd6d174466ceb1eecec7">00118</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#ab530dc092a31cd6d174466ceb1eecec7">buttonSelect</a>;
<a name="l00119"></a><a class="code" href="structt_classic_ctrl.html#a2cc9a3c8872f8aef02b6fa418fa3e263">00119</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a2cc9a3c8872f8aef02b6fa418fa3e263">buttonStart</a>;
<a name="l00120"></a><a class="code" href="structt_classic_ctrl.html#a24d6092213684644ceb9531b28e30cd3">00120</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a24d6092213684644ceb9531b28e30cd3">buttonZL</a>;
<a name="l00121"></a><a class="code" href="structt_classic_ctrl.html#a77ee770acba58304cbed503cfe706a87">00121</a>   <span class="keywordtype">bool</span> <a class="code" href="structt_classic_ctrl.html#a77ee770acba58304cbed503cfe706a87">buttonZR</a>;
<a name="l00122"></a><a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">00122</a>   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a>;
<a name="l00123"></a>00123 } <a class="code" href="structt_classic_ctrl.html">tClassicCtrl</a>;
<a name="l00124"></a>00124 
<a name="l00125"></a>00125 
<a name="l00126"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga19e0f41c4a1b6fef7d038897a48a71a6">00126</a> ubyte <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga19e0f41c4a1b6fef7d038897a48a71a6">NXTChuckIdentLookup</a>[][] = {
<a name="l00127"></a>00127   {0x00,0x00,0xA4,0x20,0x00,0x00}, <span class="comment">// Nunchuk</span>
<a name="l00128"></a>00128   {0x00,0x00,0xA4,0x20,0x01,0x01}, <span class="comment">// Classic Controller</span>
<a name="l00129"></a>00129   {0x00,0x00,0xA4,0x20,0x01,0x03}, <span class="comment">// GH3 or GHWT Guitar</span>
<a name="l00130"></a>00130   {0x01,0x00,0xA4,0x20,0x01,0x03}, <span class="comment">// Guitar Hero World Tour Drums</span>
<a name="l00131"></a>00131   {0x03,0x00,0xA4,0x20,0x01,0x03}, <span class="comment">// DJ Hero Turntable</span>
<a name="l00132"></a>00132   {0x00,0x00,0xA4,0x20,0x04,0x02}, <span class="comment">// Wii Balance Board</span>
<a name="l00133"></a>00133   {0x00,0x00,0xA4,0x20,0x04,0x05}, <span class="comment">// Activated Wii Motion Plus</span>
<a name="l00134"></a>00134   {0x00,0x00,0xA4,0x20,0x05,0x05}, <span class="comment">// Activated Wii Motion Plus in Nunchuck passthrought mode</span>
<a name="l00135"></a>00135   {0x00,0x00,0xA4,0x20,0x07,0x05}, <span class="comment">// Activated Wii Motion Plus in Classic Controller passthrought mode</span>
<a name="l00136"></a>00136   {0x00,0x00,0xA6,0x20,0x00,0x05}, <span class="comment">// Inactive Wii Motion Plus</span>
<a name="l00137"></a>00137   {0x00,0x00,0xA6,0x20,0x04,0x05}, <span class="comment">// No-longer active Wii Motion Plus</span>
<a name="l00138"></a>00138   {0x00,0x00,0xA6,0x20,0x05,0x05}, <span class="comment">// No-longer nunchuk-passthrough Wii Motion Plus</span>
<a name="l00139"></a>00139   {0x00,0x00,0xA6,0x20,0x07,0x05}, <span class="comment">// No-longer classic-passthrough Wii Motion Plus</span>
<a name="l00140"></a>00140   {0xFF,0x00,0xA4,0x20,0x00,0x00}  <span class="comment">// Seems to the ID of a black nunchuck</span>
<a name="l00141"></a>00141 };
<a name="l00142"></a>00142 
<a name="l00143"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gaf0f9c1a79b322f4e6a1513fe742f6e38">00143</a> ubyte <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaf0f9c1a79b322f4e6a1513fe742f6e38">_NXTChuckDataInit1</a>[] = {3, 0xA4, 0xF0, 0x55}; <span class="comment">/*!&lt; First of two arrays written to the extension to initialize */</span>
<a name="l00144"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga2ae1e63a60bbd730947b2b74b540c9fa">00144</a> ubyte <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga2ae1e63a60bbd730947b2b74b540c9fa">_NXTChuckDataInit2</a>[] = {3, 0xA4, 0xFB, 0x00}; <span class="comment">/*!&lt; Second of two arrays written to the extension to initialize */</span>
<a name="l00145"></a>00145 <span class="comment"></span>
<a name="l00146"></a>00146 <span class="comment">/**</span>
<a name="l00147"></a>00147 <span class="comment"> * It&#39;s a nunchuck, innit? Initialise the nunchuck sensor.</span>
<a name="l00148"></a>00148 <span class="comment"> *</span>
<a name="l00149"></a>00149 <span class="comment"> * Please note that this is an internal function and should not called directly.</span>
<a name="l00150"></a>00150 <span class="comment"> * @param link the NXTChuck port number</span>
<a name="l00151"></a>00151 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00152"></a>00152 <span class="comment"> */</span>
<a name="l00153"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga4e27c0e1d759013fdb41c31635d9e937">00153</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga4e27c0e1d759013fdb41c31635d9e937">_NXTChuckInit</a>(tSensors link){
<a name="l00154"></a>00154   writeDebugStreamLine(<span class="stringliteral">&quot;initialising&quot;</span>);
<a name="l00155"></a>00155     memcpy(<a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>, <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaf0f9c1a79b322f4e6a1513fe742f6e38">_NXTChuckDataInit1</a>, <span class="keyword">sizeof</span>(<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaf0f9c1a79b322f4e6a1513fe742f6e38">_NXTChuckDataInit1</a>));
<a name="l00156"></a>00156     <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>))
<a name="l00157"></a>00157       <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00158"></a>00158 
<a name="l00159"></a>00159     memcpy(<a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>, <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga2ae1e63a60bbd730947b2b74b540c9fa">_NXTChuckDataInit2</a>, <span class="keyword">sizeof</span>(<a class="code" href="group___n_x_t_c_h_u_c_k.html#ga2ae1e63a60bbd730947b2b74b540c9fa">_NXTChuckDataInit2</a>));
<a name="l00160"></a>00160     <span class="keywordflow">return</span> <a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>);
<a name="l00161"></a>00161 }
<a name="l00162"></a>00162 <span class="comment"></span>
<a name="l00163"></a>00163 <span class="comment">/**</span>
<a name="l00164"></a>00164 <span class="comment"> * Read 6 bytes from the nunchuck and return it.</span>
<a name="l00165"></a>00165 <span class="comment"> *</span>
<a name="l00166"></a>00166 <span class="comment"> * Please note this is an internal function and should not be used directly.</span>
<a name="l00167"></a>00167 <span class="comment"> * @param link the nunchuck port number</span>
<a name="l00168"></a>00168 <span class="comment"> * @param _reg the register to read</span>
<a name="l00169"></a>00169 <span class="comment"> * @param data the tByteArray to hold the returned data</span>
<a name="l00170"></a>00170 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00171"></a>00171 <span class="comment"> */</span>
<a name="l00172"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#gad95cda163b90b57e7439f877f2680a6d">00172</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t_c_h_u_c_k.html#gad95cda163b90b57e7439f877f2680a6d">__NXTChuckReadRaw</a>(tSensors link, ubyte _reg, <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> &amp;data){
<a name="l00173"></a>00173   <span class="keywordflow">if</span> (!<a class="code" href="group___n_x_t_c_h_u_c_k.html#gad9e05a633482cf59f2ab2d4976d64bb1">NXTCHUCKinitialised</a>[link])
<a name="l00174"></a>00174   {
<a name="l00175"></a>00175     <span class="keywordflow">if</span> (!<a class="code" href="group___n_x_t_c_h_u_c_k.html#ga4e27c0e1d759013fdb41c31635d9e937">_NXTChuckInit</a>(link))
<a name="l00176"></a>00176       <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00177"></a>00177 
<a name="l00178"></a>00178     <a class="code" href="group___n_x_t_c_h_u_c_k.html#gad9e05a633482cf59f2ab2d4976d64bb1">NXTCHUCKinitialised</a>[link] = <span class="keyword">true</span>;
<a name="l00179"></a>00179   }
<a name="l00180"></a>00180 
<a name="l00181"></a>00181   <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>[0] = 2;
<a name="l00182"></a>00182   <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>[1] = <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga33b0a41cd83100cfdc42bc534d47e0f5">NXTCHUCK_I2C_ADDRESS</a>;
<a name="l00183"></a>00183   <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>[2] = _reg;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>))
<a name="l00186"></a>00186     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00187"></a>00187 
<a name="l00188"></a>00188   <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>[0] = 1;
<a name="l00189"></a>00189   <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>[1] = <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga33b0a41cd83100cfdc42bc534d47e0f5">NXTCHUCK_I2C_ADDRESS</a>;
<a name="l00190"></a>00190 
<a name="l00191"></a>00191   <span class="keywordflow">return</span> <a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga5a169244d76717a9303d2c6f7bf10770">NXTCHUCK_I2CRequest</a>, data, 6);
<a name="l00192"></a>00192 }
<a name="l00193"></a>00193 
<a name="l00194"></a>00194 <span class="comment"></span>
<a name="l00195"></a>00195 <span class="comment">/**</span>
<a name="l00196"></a>00196 <span class="comment"> * Identify the type of nunchuck sensor connected to the NXT.</span>
<a name="l00197"></a>00197 <span class="comment"> * @param link the nunchuck port number</span>
<a name="l00198"></a>00198 <span class="comment"> * @param nunchuck the tNunchuck that holds the nunchuck related data.</span>
<a name="l00199"></a>00199 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00200"></a>00200 <span class="comment"> */</span>
<a name="l00201"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga7e7456a1ff24dfebe5e3fde04cc2fa71">00201</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga7e7456a1ff24dfebe5e3fde04cc2fa71">NXTChuckreadIdent</a>(tSensors link, <a class="code" href="structt_nunchuck.html">tNunchuck</a> &amp;nunchuck){
<a name="l00202"></a>00202   <span class="keywordflow">if</span>(<a class="code" href="group___n_x_t_c_h_u_c_k.html#gad95cda163b90b57e7439f877f2680a6d">__NXTChuckReadRaw</a>(link, 0xFA, <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>)){
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 <span class="preprocessor">#ifdef __NUNHUCK__DEBUG__</span>
<a name="l00205"></a>00205 <span class="preprocessor"></span>    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; 6; i++)
<a name="l00206"></a>00206     {
<a name="l00207"></a>00207       writeDebugStream(<span class="stringliteral">&quot;0x%02X &quot;</span>, <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[i]);
<a name="l00208"></a>00208     }
<a name="l00209"></a>00209 
<a name="l00210"></a>00210     writeDebugStreamLine(<span class="stringliteral">&quot; &quot;</span>);
<a name="l00211"></a>00211 <span class="preprocessor">#endif // __NUNHUCK__DEBUG__</span>
<a name="l00212"></a>00212 <span class="preprocessor"></span>
<a name="l00213"></a>00213     <span class="keywordflow">for</span>(byte i = 0; i &lt; 14; i++){
<a name="l00214"></a>00214 
<a name="l00215"></a>00215 <span class="preprocessor">#ifdef __NUNHUCK__DEBUG__</span>
<a name="l00216"></a>00216 <span class="preprocessor"></span>      writeDebugStream(<span class="stringliteral">&quot;Comparing: &quot;</span>);
<a name="l00217"></a>00217       <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j &lt; 6; j++)
<a name="l00218"></a>00218       {
<a name="l00219"></a>00219         writeDebugStream(<span class="stringliteral">&quot;0x%02X &quot;</span>, <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[j]);
<a name="l00220"></a>00220       }
<a name="l00221"></a>00221       writeDebugStream(<span class="stringliteral">&quot;   and   &quot;</span>);
<a name="l00222"></a>00222       <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j &lt; 6; j++)
<a name="l00223"></a>00223       {
<a name="l00224"></a>00224         writeDebugStream(<span class="stringliteral">&quot;0x%02X &quot;</span>, <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga19e0f41c4a1b6fef7d038897a48a71a6">NXTChuckIdentLookup</a>[i][j]);
<a name="l00225"></a>00225       }
<a name="l00226"></a>00226       writeDebugStreamLine(<span class="stringliteral">&quot;: %d&quot;</span>, memcmp(&amp;<a class="code" href="group___n_x_t_c_h_u_c_k.html#ga19e0f41c4a1b6fef7d038897a48a71a6">NXTChuckIdentLookup</a>[i][0], &amp;<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[0], 6));
<a name="l00227"></a>00227 <span class="preprocessor">#endif // __NUNHUCK__DEBUG__</span>
<a name="l00228"></a>00228 <span class="preprocessor"></span>
<a name="l00229"></a>00229       <span class="keywordflow">if</span> (memcmp(&amp;<a class="code" href="group___n_x_t_c_h_u_c_k.html#ga19e0f41c4a1b6fef7d038897a48a71a6">NXTChuckIdentLookup</a>[i][0], &amp;<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[0], 6) == 0)
<a name="l00230"></a>00230       {
<a name="l00231"></a>00231         nunchuck.<a class="code" href="structt_nunchuck.html#a52c92ae81f8d5f16d15422fb3838fe27">ident</a> = i + 2;
<a name="l00232"></a>00232         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00233"></a>00233       }
<a name="l00234"></a>00234     }
<a name="l00235"></a>00235     nunchuck.<a class="code" href="structt_nunchuck.html#a52c92ae81f8d5f16d15422fb3838fe27">ident</a> = <a class="code" href="group___n_x_t_c_h_u_c_k.html#gadfa14694b133a4c3cfdcb4e80548903e">NXTCHUCK_DEVICE_UNKNOWN</a>;
<a name="l00236"></a>00236     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00237"></a>00237   }
<a name="l00238"></a>00238   <span class="keywordflow">return</span> <span class="keyword">false</span>;                                                    <span class="comment">// Communication error</span>
<a name="l00239"></a>00239 }
<a name="l00240"></a>00240 
<a name="l00241"></a>00241 <span class="comment"></span>
<a name="l00242"></a>00242 <span class="comment">/**</span>
<a name="l00243"></a>00243 <span class="comment"> * Read the data from the nunchuck.</span>
<a name="l00244"></a>00244 <span class="comment"> * @param link the nunchuck port number</span>
<a name="l00245"></a>00245 <span class="comment"> * @param nunchuck the tNunchuck that holds the nunchuck related data.</span>
<a name="l00246"></a>00246 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00247"></a>00247 <span class="comment"> */</span>
<a name="l00248"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga763586a19d4de3dcd3e74c43ec15f82d">00248</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga763586a19d4de3dcd3e74c43ec15f82d">NXTChuckreadSensor</a>(tSensors link, <a class="code" href="structt_nunchuck.html">tNunchuck</a> &amp;nunchuck){
<a name="l00249"></a>00249   <span class="keywordflow">if</span>(<a class="code" href="group___n_x_t_c_h_u_c_k.html#gad95cda163b90b57e7439f877f2680a6d">__NXTChuckReadRaw</a>(link, 0x00, <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>))
<a name="l00250"></a>00250   {
<a name="l00251"></a>00251     nunchuck.<a class="code" href="structt_nunchuck.html#aec86757fae7769579f06ae433a0a5d44">stickX</a> = <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[0];
<a name="l00252"></a>00252     nunchuck.<a class="code" href="structt_nunchuck.html#a91804e03b8050dbb60a0097eda903f57">stickY</a> = <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[1];
<a name="l00253"></a>00253 
<a name="l00254"></a>00254     nunchuck.<a class="code" href="structt_nunchuck.html#aeb96883d9be554e3130dd8a074dd1181">accelX</a> = (<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[2] &lt;&lt; 2) | ((<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[5] &gt;&gt; 2) &amp; 0x03);
<a name="l00255"></a>00255     nunchuck.<a class="code" href="structt_nunchuck.html#aa79b1c1093bc17ca66f39fa286fb8c16">accelY</a> = (<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[3] &lt;&lt; 2) | ((<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[5] &gt;&gt; 4) &amp; 0x03);
<a name="l00256"></a>00256     nunchuck.<a class="code" href="structt_nunchuck.html#ac1d83c37ada1e57ee781a2e8eea0472a">accelZ</a> = (<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[4] &lt;&lt; 2) | ((<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[5] &gt;&gt; 6) &amp; 0x03);
<a name="l00257"></a>00257 
<a name="l00258"></a>00258     nunchuck.<a class="code" href="structt_nunchuck.html#acfe810cf5fd316d47ead62fa49987852">buttons</a> = (~<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[5]) &amp; 0x03;
<a name="l00259"></a>00259     nunchuck.<a class="code" href="structt_nunchuck.html#a739999c8e3c48d0a6a60783b778c4a6b">buttonC</a> = (nunchuck.<a class="code" href="structt_nunchuck.html#acfe810cf5fd316d47ead62fa49987852">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gabf57486ae72c2255ae1870b5f1b6d2d3">NXTCHUCK_N_BTN_C</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00260"></a>00260     nunchuck.<a class="code" href="structt_nunchuck.html#ad21c5419fe7bae1473d6b2a153a89a2e">buttonZ</a> = (nunchuck.<a class="code" href="structt_nunchuck.html#acfe810cf5fd316d47ead62fa49987852">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga0db481094e42ec52acef7ea369fec78f">NXTCHUCK_N_BTN_Z</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00261"></a>00261 
<a name="l00262"></a>00262     <span class="keywordflow">return</span> <span class="keyword">true</span>;                                            <span class="comment">// Return success</span>
<a name="l00263"></a>00263   }
<a name="l00264"></a>00264   <span class="keywordflow">return</span> <span class="keyword">false</span>;                                                  <span class="comment">// Return error</span>
<a name="l00265"></a>00265 }
<a name="l00266"></a>00266 
<a name="l00267"></a>00267 <span class="comment"></span>
<a name="l00268"></a>00268 <span class="comment">/**</span>
<a name="l00269"></a>00269 <span class="comment"> * Read the data from the classic controller.</span>
<a name="l00270"></a>00270 <span class="comment"> * @param link the nunchuck port number</span>
<a name="l00271"></a>00271 <span class="comment"> * @param controller the tClassicCtrl that holds the Classic Controller related data.</span>
<a name="l00272"></a>00272 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00273"></a>00273 <span class="comment"> */</span>
<a name="l00274"></a><a class="code" href="group___n_x_t_c_h_u_c_k.html#ga9b4d2dc377ab2effae7e0db8a93fc6d6">00274</a> <span class="keywordtype">bool</span> <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga9b4d2dc377ab2effae7e0db8a93fc6d6">NXTChuckReadClassicController</a>(tSensors link, <a class="code" href="structt_classic_ctrl.html">tClassicCtrl</a> &amp;controller){
<a name="l00275"></a>00275   <span class="keywordflow">if</span>(<a class="code" href="group___n_x_t_c_h_u_c_k.html#gad95cda163b90b57e7439f877f2680a6d">__NXTChuckReadRaw</a>(link, 0x00, <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>))
<a name="l00276"></a>00276   {
<a name="l00277"></a>00277     controller.<a class="code" href="structt_classic_ctrl.html#a9b14fccdc6066b2e7e3a5deea31b7567">stickLX</a> = <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[0] &amp; 0x3F;                                        <span class="comment">// Unpack the data into usable values</span>
<a name="l00278"></a>00278     controller.<a class="code" href="structt_classic_ctrl.html#ab96192459caf58af8ba8ed4d7367b4ee">stickLY</a> = <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[1] &amp; 0x3F;
<a name="l00279"></a>00279     controller.<a class="code" href="structt_classic_ctrl.html#a07c1c7c15c0af0dd74ce953e121efae5">triggerL</a> = ((<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[2] &gt;&gt; 2) &amp; 0x18) | ((<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[3] &gt;&gt; 5) &amp; 0x07);
<a name="l00280"></a>00280 
<a name="l00281"></a>00281     controller.<a class="code" href="structt_classic_ctrl.html#a2677c7490918757766a0f7b801602278">stickRX</a> = ((<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[0] &gt;&gt; 3) &amp; 0x18) | ((<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[1] &gt;&gt; 5) &amp; 0x06) | ((<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[2] &gt;&gt; 7) &amp; 0x01);
<a name="l00282"></a>00282     controller.<a class="code" href="structt_classic_ctrl.html#a39a37e31fa3e3fae864ce87bcdb5ff71">stickRY</a> = <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[2] &amp; 0x1F;
<a name="l00283"></a>00283     controller.<a class="code" href="structt_classic_ctrl.html#a212e8e42339fc291fd4406046df4f34a">triggerR</a> = <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[3] &amp; 0x1F;
<a name="l00284"></a>00284 
<a name="l00285"></a>00285     controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> = ~(<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[4] | (<a class="code" href="group___n_x_t_c_h_u_c_k.html#gaacae0addfc9b80bc34eb4dbf669586a4">NXTCHUCK_I2CReply</a>[5] &lt;&lt; 8)) &amp; 0xFFFE;
<a name="l00286"></a>00286 
<a name="l00287"></a>00287     controller.<a class="code" href="structt_classic_ctrl.html#a8b6b2540b59302ca57e29f788de1c5cc">buttonTriggerR</a> = (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gad0a04982202449af8b35fccc3388d7e5">NXTCHUCK_CC_BTN_RT</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00288"></a>00288     controller.<a class="code" href="structt_classic_ctrl.html#a9c7f8c6a2b4a93c605ba1083e98d1197">buttonTriggerL</a> = (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga2e68a6268d949d5bebe54c5a688ba293">NXTCHUCK_CC_BTN_LT</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00289"></a>00289 
<a name="l00290"></a>00290     controller.<a class="code" href="structt_classic_ctrl.html#a6f435816b6dba2536203fe937c5a7905">buttonDPadU</a> =    (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gade1d4765de012f6b24581ef4f3f8225f">NXTCHUCK_CC_BTN_DU</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00291"></a>00291     controller.<a class="code" href="structt_classic_ctrl.html#a1ac9574aa7f0abb76f9ca882437aa661">buttonDPadD</a> =    (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gaf9935a7d30f2ebeb442a403cf1a17557">NXTCHUCK_CC_BTN_DD</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00292"></a>00292     controller.<a class="code" href="structt_classic_ctrl.html#a35a67166ed212a30cbcb025c9a33488b">buttonDPadL</a> =    (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gac3e7e295b742d51958d4fc52754ecc80">NXTCHUCK_CC_BTN_DL</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00293"></a>00293     controller.<a class="code" href="structt_classic_ctrl.html#abeb7d81a3d8ea072dbd803d84a36e7ad">buttonDPadR</a> =    (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gad0e67c5290b53525437db9005acefd69">NXTCHUCK_CC_BTN_DR</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00294"></a>00294 
<a name="l00295"></a>00295     controller.<a class="code" href="structt_classic_ctrl.html#a4b81f62849de94e99031a75408ed1c5b">buttonX</a> =        (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga18688c1612146737edb1238d228cad62">NXTCHUCK_CC_BTN_X</a>)  ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00296"></a>00296     controller.<a class="code" href="structt_classic_ctrl.html#a88fccb9b936b98239e4c80bb45a7f2e4">buttonA</a> =        (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gac62af2bf82e90f0d87345e50c5d90631">NXTCHUCK_CC_BTN_A</a>)  ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00297"></a>00297     controller.<a class="code" href="structt_classic_ctrl.html#a0a2aeff8c72c86f513929868343e5f60">buttonY</a> =        (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gab16f06d45d67248b1a3358687d13ac22">NXTCHUCK_CC_BTN_Y</a>)  ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00298"></a>00298     controller.<a class="code" href="structt_classic_ctrl.html#a47d83cca9ce8707970aa544ef790997f">buttonB</a> =        (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga10574eabab0f5905a30bb98efa349e99">NXTCHUCK_CC_BTN_B</a>)  ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00299"></a>00299 
<a name="l00300"></a>00300     controller.<a class="code" href="structt_classic_ctrl.html#a3fa408e11ec1e44f7a065534b7e9abb0">buttonHome</a> =     (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gae87e9ee4f20c42e5f296827b08f69208">NXTCHUCK_CC_BTN_H</a>)  ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00301"></a>00301     controller.<a class="code" href="structt_classic_ctrl.html#ab530dc092a31cd6d174466ceb1eecec7">buttonSelect</a> =   (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gad0a04982202449af8b35fccc3388d7e5">NXTCHUCK_CC_BTN_RT</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00302"></a>00302     controller.<a class="code" href="structt_classic_ctrl.html#a2cc9a3c8872f8aef02b6fa418fa3e263">buttonStart</a> =    (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#ga9c48c4368a4519495ed768ce1dd2b54d">NXTCHUCK_CC_BTN_P</a>)  ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00303"></a>00303 
<a name="l00304"></a>00304     controller.<a class="code" href="structt_classic_ctrl.html#a24d6092213684644ceb9531b28e30cd3">buttonZL</a> =       (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gad0a04982202449af8b35fccc3388d7e5">NXTCHUCK_CC_BTN_RT</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00305"></a>00305     controller.<a class="code" href="structt_classic_ctrl.html#a77ee770acba58304cbed503cfe706a87">buttonZR</a> =       (controller.<a class="code" href="structt_classic_ctrl.html#ad8caf068f1c5cc96e1ee744e8dea493d">buttons</a> &amp; <a class="code" href="group___n_x_t_c_h_u_c_k.html#gad0a04982202449af8b35fccc3388d7e5">NXTCHUCK_CC_BTN_RT</a>) ? <span class="keyword">true</span> : <span class="keyword">false</span>;
<a name="l00306"></a>00306 
<a name="l00307"></a>00307     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00308"></a>00308   }
<a name="l00309"></a>00309   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00310"></a>00310 }
<a name="l00311"></a>00311 
<a name="l00312"></a>00312 
<a name="l00313"></a>00313 <span class="preprocessor">#endif // __NXTCHUCK_H__</span>
<a name="l00314"></a>00314 <span class="preprocessor"></span>
<a name="l00315"></a>00315 <span class="comment">/*</span>
<a name="l00316"></a>00316 <span class="comment"> * $Id: dexterind-nxtchuck.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00317"></a>00317 <span class="comment"> */</span>
<a name="l00318"></a>00318 <span class="comment">/* @} */</span>
<a name="l00319"></a>00319 <span class="comment">/* @} */</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
